package com.hnguigu.ajax.controller;

import com.hnguigu.ajax.entity.City;
import com.hnguigu.ajax.entity.Country;
import com.hnguigu.ajax.service.CountryService;
import com.hnguigu.ajax.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/country")
public class CountryController {

    @Autowired
    private CountryService countryService;

    @RequestMapping("/cascade")
    public String cascade() {
        return "cascade";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Result<List<Country>> list() {
        return new Result<>("true", "2000", "查询国家列表成功！", this.countryService.findAll());
    }

    @RequestMapping("/findCityListById/{id}")
    @ResponseBody
    public Result<List<City>> findCityListById(@PathVariable Integer id) {
        return new Result<>("true", "2000", "根据国家编号查询城市列表成功！", this.countryService.findCityListById(id));
    }
}
